import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Home',
        component: () =>
            import ('../views/Home.vue'),
    },
    {
        path: '/about',
        name: 'About',
        component: () =>
            import ( /* webpackChunkName: "about" */ '../views/About.vue'),
    },
    {
        path: '/logo/sign', //登录
        name: 'Sign',
        component: () =>
            import ('../views/logo/Sign.vue'),
    },
    {
        path: '/logo/regist', //注册
        name: 'Regist',
        component: () =>
            import ('../views/logo/Regist.vue'),
    },
    {
        path: '/index/index', //主页
        name: 'Index',
        component: () =>
            import ('../views/index/Index.vue'),
    },
    {
        path: '/index/bidding', //招标大厅
        name: 'Bidding',
        component: () =>
            import ('../views/index/Bidding.vue'),
    },
    {
        path: '/index/bidding-details', //招标
        name: 'Bidding-details',
        component: () =>
            import ('../views/index/Bidding-details.vue'),
    },
    {
        path: '/index/workbench', //工作台
        name: 'Workbench',
        component: () =>
            import ('../views/index/Workbench.vue'),
    }
]

const router = new VueRouter({
    routes
})
router.beforeEach((to, from, next) => {
    var n = localStorage.getItem('logo'); //登录保存在本地
    var b = localStorage.getItem('ind'); //如果不登录，让他访问
    if (n != null) {
        next();
    } else {
        if (to.name == 'Sign' || to.name == 'Regist' || to.name == 'Bidding-details') { //如果是登录或者注册页面，放行
            next();
        } else {
            if (to.name == 'Index') { //进入主页判断是否登录过
                if (b != null) { //进入主页判断是否取消过登录
                    next();
                } else {
                    var a = confirm('确定登录吗？');
                    if (a) {
                        next('/logo/sign');
                    } else {
                        localStorage.setItem('ind', 'ind');
                        next();
                    }
                }
            }
        }
    }
})

export default router